package com.cbg.base.core;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <pre>通用实体抽象基类</pre>
 * <small> 2018-10-28 | chenbing </small>
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public abstract  class  SuperEntity<T extends Model> extends Model<T>{
    @TableId(type = IdType.ID_WORKER_STR)
    private String id;

    /**
     * 创建时间
     */
    @JSONField(serialize = false)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createAt;

    /**
     * 更新时间
     */
    @JSONField(serialize = false)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime updateAt;

    /**
     * 逻辑删除，0为未删除，1为已删除
     */
    @TableLogic
    @JSONField(serialize = false)
    private boolean isDel;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
